package com.delta.controller.houseInfo;

import java.util.Map;

import com.delta.bean.houseInfo.HouseInfoBean;
import com.delta.service.houseInfo.HouseInfoService;
import com.github.pagehelper.PageInfo;
import com.delta.base.BaseController;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;


/**
 *<pre>
 *  HouseInfo Controller
 *  通过 lion generator 生成，禁止使用商业
 *  时间: 2017-57-19 14:57:21
 *</pre>
 * @author lion
 * @version 1.0
**/


@Controller
@RequestMapping("houseInfo")
public class HouseInfoController extends BaseController{
	/**service服务类**/
	@Autowired
	private HouseInfoService houseInfoService;


	/**列表**/
	@RequestMapping("list")
	public String getHouseInfoList(Model model,HouseInfoBean bean){
		bean.prepareData();
		PageInfo pageInfo = houseInfoService.getHouseInfoListByBean(bean);
		model.addAttribute("data", pageInfo); 
		model.addAttribute("query", bean); 
		return "/houseInfo/list";
	}

	/**根据id获取对象**/
	@RequestMapping("getBeanById")
	public String getHouseInfoBeanById(Model model,HouseInfoBean bean){
		if(bean.getId() != null){
			bean = houseInfoService.getHouseInfoBeanById(bean);
		}
		model.addAttribute("houseInfo", bean); 
		return "/houseInfo/info";
	}

	/***新增 或修改**/
	@RequestMapping("addOrModify")
	@ResponseBody()
	public Map addHouseInfoBean(HouseInfoBean bean){
		try{

		bean.prepareData();
			houseInfoService.addOrModifyHouseInfoByBean(bean);

		}catch(Exception e){
			return super.getFailureInfo();
		}
		return super.getSuccessInfo();
	}

	/**删除**/
	@RequestMapping("delete")
	@ResponseBody()
	public Map deleteHouseInfoBean(HouseInfoBean bean){
		try{

			houseInfoService.deleteHouseInfoByBean(bean);

		}catch(Exception e){
			return super.getFailureInfo();
		}
		return super.getSuccessInfo();
	}

}
